/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gla.centralhotel.dao;

import gla.centralhotel.dao.interfaces.IRoomTypeDAO;
import gla.centralhotel.model.RoomType;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Rivo
 */
@Stateless
public class RoomTypeDAO implements IRoomTypeDAO {
    @PersistenceContext
    private EntityManager em;

    @Override
    public void create(RoomType roomType) {
        em.persist(roomType);
    }

    @Override
    public void edit(RoomType roomType) {
        em.merge(roomType);
    }

    @Override
    public void remove(RoomType roomType) {
        em.remove(em.merge(roomType));
    }

    @Override
    public RoomType find(Object id) {
        return em.find(gla.centralhotel.model.RoomType.class, id);
    }

    @Override
    public List<RoomType> findAll() {
        return em.createQuery("select object(o) from RoomType as o").getResultList();
    }
    
    public RoomType saveRoomType(RoomType type){
        
        return null;
    }
    
    public ArrayList<RoomType> getAllRoomType(){
        return new ArrayList(findAll());
    }

    /**
     * meme effet que la methode find(Object id) a l'exception que les attribut transiant
     * count
     * sont remplit par les donnée de la base
     * @param id
     * @return
     */
//    @Override
//    public RoomType find_(Object id)
//    {
//        RoomType t = this.find(id);
//        Collection<Room> rc =  t.getRoomCollection();
//        t.setCount(rc.size());
//        return t;
//    }
    
    /**
     * meme effet que la methode findAll() a l'exception que les attribut transiant
     * count
     * sont remplit par les donnée de la base
     * @return
     */
//    @Override
//    public List<RoomType> findAll_() 
//    {
//        List<RoomType> lrt = this.findAll();
//        for (int i = 0; i < lrt.size(); i++)
//        {
//            RoomType rt = lrt.get(i);
//            Collection<Room> rc =  rt.getRoomCollection();
//            rt.setCount(rc.size());
//            lrt.set(i, rt);
//        }
//        return lrt;
//    }
    
}
